package com.agentlab.imitation.service;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.agentlab.imitation.bean.DimDydm;
import com.agentlab.imitation.service.base.DaoSupport;

@Service
@Transactional
public class DimDydmServiceBean extends DaoSupport<DimDydm> implements DimDydmService {
	@Resource
	SessionFactory factory;

	public void delete(Serializable... entityids) {
		// TODO Auto-generated method stub

	}

	@SuppressWarnings("unchecked")
	public String getDymcByDydm(String dm) {
		String dymc = "";
		if(dm != null && !dm.equals("")){
			String[]  diyus = dm.split("|"); 
			for(String str:diyus){
				List<DimDydm> list = factory.getCurrentSession().createQuery(" from DimDydm a where a.dm = :dm ").setParameter("dm", dm).list();
				if (list.size() > 0) {
					DimDydm dy = list.get(0);
					dymc += "'"+ dy.getMc() + "',";
				}
			}
			if(!dymc.equals(""))dymc = dymc.substring(0, dymc.length() - 1);
		}
		System.out.println("DimDydmServiceBean.getDymcByDydm() dymc="+dymc);
		return dymc;
	}

}
